/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package com.nhc.model;

import android.location.Location;

import com.astrob.model.LonLat;
import com.astrob.util.SysUtils;
import com.astrob.util.Utils;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;

import zuo.biao.library.base.BaseModel;
import zuo.biao.library.model.Entry;

public class HCLocationInfo extends BaseModel {

    private static final long serialVersionUID = 1L;

    private String city = "";
    private double lon = 0.0;
    private double lat = 0.0;

    private String UtmZone = "";

    int coord_format = 0;

    /**
     * 默认构造方法，JSON等解析时必须要有
     */
    public HCLocationInfo() {
        //default
    }

    public HCLocationInfo(long id) {
        this();
        this.id = id;
    }

    public HCLocationInfo(String cityname, LonLat ll, String UtmZone, int coord_format) {
        this();
        this.city = "";
        if (cityname != null) {
            this.city = cityname;
        }
        this.UtmZone = "";
        if (UtmZone != null) {
            this.UtmZone = UtmZone;
        }

        this.coord_format = coord_format;
        setLL(ll);
    }

    public LonLat getLL() {
        return new LonLat(lon, lat);
    }

    public Map<String, String> getLLDMS() {
        switch (coord_format) {
            case 0:
            case 1:
            case 2:
                return Utils.LL2DMS(getLL());
            case 3://UTM
            case 4:
                return getLLStr();
        }
        return Utils.LL2DMS(getLL());
    }

    public Map<String, String> getLLStr() {
        Map<String, String> XX = new HashMap<String, String>();

        String strLon = new DecimalFormat("0.000").format(Math.abs(lon)) + (lon > 0 ? " E" : " W");
        String strLat = new DecimalFormat("0.000").format(Math.abs(lat)) + (lat > 0 ? " N" : " S");
//		String strLon = Math.abs(lon) + (lon > 0 ? " E" : " W");
//		String strLat = Math.abs(lat) + (lat > 0 ? " N" : " S");

        if (UtmZone.length() > 0) {
            XX.put("lon", UtmZone + " " + strLon);
        } else {
            XX.put("lon", strLon);
        }

        XX.put("lat", strLat);

        return XX;
    }

    public void setLL(LonLat ll) {
        if (ll != null) {
            lon = ll.GetLon();
            lat = ll.GetLat();
        }
    }

    public void setLL(double llon, double llat) {
        lon = llon;
        lat = llat;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    /**
     * 以下getter和setter可以自动生成
     * <br>  eclipse: 右键菜单 > Source > Generate Getters and Setters
     * <br>  android studio: 右键菜单 > Generate > Getter and Setter
     */


    @Override
    protected boolean isCorrect() {//根据自己的需求决定，也可以直接 return true
        return id > 0;// && StringUtil.isNotEmpty(phone, true);
    }

}
